float4x4 World;
float4x4 View;
float4x4 Projection;


texture2D normalmap;

sampler2D normaltex = sampler_state 
{
    texture = normalmap;
    AddressU = WRAP;
    AddressV = WRAP;
    FILTER = LINEAR;
};

texture2D projtex;

sampler2D projtexture = sampler_state
{
    texture = projtex;
    AddressU = CLAMP;
    AddressV = CLAMP;
    FILTER = LINEAR;
};

texture2D Diffuse;

sampler2D ColorMapSampler = sampler_state 
{
    texture = Diffuse;
    AddressU = CLAMP;
    AddressV = CLAMP;
    FILTER = POINT;
};

texture2D position;

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float3 TexCoords : TEXCOORD0;
    float3 Normal : NORMAL0;

    // TODO: add input channels such as texture
    // coordinates and vertex colors here.
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float3 TexCoords : TEXCOORD0;
    float3 Normal : TEXCOORD1;
    float3 Wpos : TEXCOORD2;
    // TODO: add vertex shader outputs such as colors and texture
    // coordinates here. These values will automatically be interpolated
    // over the triangle, and provided as input to your pixel shader.
};

/*VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    return output;
}*/

VertexShaderOutput VertexShaderFunctionOOC(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    output.TexCoords = input.TexCoords;
    output.Normal = mul(input.Normal, World);
    output.Wpos = worldPosition;

    return output;
}

/*float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    // TODO: add your pixel shader code here.

    return float4(1, 1, 0, 1);
}*/

float4 PixelShaderFunctionOOC(VertexShaderOutput input) : COLOR0
{
    return tex2D(ColorMapSampler, input.TexCoords);
}

float4 PixelShaderFunctionFilter(VertexShaderOutput input) : COLOR0
{
    // GreyScale
    /*float4 color = tex2D(ColorMapSampler, input.TexCoords);
    
    return dot(color, float4(0.3, 0.59, 0.11, 0.0));*/

    // Bluring
    float BlurDistance = 0.002f;
    float2 Tex = input.TexCoords;
    
    float4 color = tex2D(ColorMapSampler, float2(Tex.x+BlurDistance, Tex.y+BlurDistance));
    color += tex2D(ColorMapSampler, float2(Tex.x-BlurDistance, Tex.y-BlurDistance));
    color += tex2D(ColorMapSampler, float2(Tex.x+BlurDistance, Tex.y-BlurDistance));
    color += tex2D(ColorMapSampler, float2(Tex.x-BlurDistance, Tex.y+BlurDistance));
    color = color / 4;

    return color;
}

/*technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_3_0 VertexShaderFunction();
        PixelShader = compile ps_3_0 PixelShaderFunction();
    }
}*/

technique OOC
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_3_0 VertexShaderFunctionOOC();
        PixelShader = compile ps_3_0 PixelShaderFunctionFilter();
    }
}
